(function() { window.FS = window.FS || {}; window.FS.GDPR = window.FS.GDPR || {}; //Add Footer button before adding the script //check if we're on a 3.0 page, rbf has it added directly var legalList = document.querySelector("ul.PageFooter-legal"); if (!!legalList) { var listItem = document.createElement("li"); listItem.classList.add("PageFooter-legalItem", "ty-c4"); listItem.innerHTML = ''; var legalLinks = legalList.querySelectorAll("li.PageFooter-legalItem"); if (legalLinks.length > 2) { legalList.insertBefore(listItem, legalLinks[2]); } else { legalList.appendChild(listItem); } } //Called whenever consent is changed var onChangeCbs = []; window.FS.GDPR.onConsentChange = function(cb) { onChangeCbs.push(cb); }; //Called when active groups is loaded var getSavedCbs = []; window.FS.GDPR.getSavedConsent = function(cb) { if (window["OnetrustActiveGroups"]) { cb(getCookieCategories(window["OnetrustActiveGroups"].split(","))); } else { getSavedCbs.push(cb); } }; //Call the cb immediately if groups are already loaded and the specified category is active //Otherwise queue it and check when OneTrust has loaded var activeCategoryCbs = {}; window.FS.GDPR.ifAllowed = function(category, cb) { if (window["OnetrustActiveGroups"]) { var cookieCategories = getCookieCategories( window["OnetrustActiveGroups"] ); if (cookieCategories[category]) { cb(); } } else { if (activeCategoryCbs[category]) { activeCategoryCbs[category].push(cb); } else { activeCategoryCbs[category] = [cb]; } } }; // this just serves as a cache record of which scripts have been loaded so we don't end up trying to load the same script multiple times. const loadedScripts = {}; /** * * @param {*} scriptOptions: script: path to script, async: whether to load asn * @param {*} requiredCategory: which category need to be checked * @param {*} ifAllowed: cb function called if the script is added to the page. This does not necessarily mean the script has LOADED though. Implementing code will need to handle whether the script has loaded or not. * @param {*} ifNot : cb function called if the script is not added to the page */ window.FS.GDPR.loadScript = function( { script, tagOptions = {} }, requiredCategory, ifAllowed = () => {}, ifNot = () => {} ) { window.FS.GDPR.getSavedConsent((consentStatus) => { if (consentStatus[requiredCategory]) { if (!loadedScripts[script]) { var tag = document.createElement("script"); tag.src = script; Object.keys(tagOptions).forEach((option) => { tag[option] = tagOptions[option]; }); var firstScriptTag = document.getElementsByTagName("script")[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); //record that we've loaded this script loadedScripts[script] = true; } ifAllowed(); } else { ifNot(); } }); }; var script = document.createElement("script"); script.type = "text/javascript"; script.charset = "UTF-8"; script.dataset.documentLanguage = true; script.src = "https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"; script.dataset.domainScript = "9e48cc7d-034f-4801-a2a7-b5b0c39710cc"; var wrapper = document.createElement("script"); wrapper.type = "text/javascript"; wrapper.innerHTML = "function OptanonWrapper() { }"; document.head.insertBefore(wrapper, document.head.firstChild); document.head.insertBefore(script, document.head.firstChild); //Remove the old banner var bannerCss = document.querySelector("div[fs-gdpr-banner]") || document.querySelector('link[href*="/alt/fshr/shared/css/gdpr-banner"'); var bannerHtml = document.getElementById("GdprCookieBanner"); if (bannerCss) bannerCss.remove(); if (bannerHtml) bannerHtml.remove(); var getCookieCategories = function(groups) { groups = groups || []; return { necessary: groups.includes("C0001"), performance: groups.includes("C0002"), functional: groups.includes("C0003"), ads: groups.includes("C0004"), social: groups.includes("C0005"), }; }; //poll every half second for 30 seconds var maxWaitTime = 30000; var waitFor = function(valueName, cb, timeoutCb, timeStarted) { timeStarted = timeStarted || new Date().getTime(); if (window[valueName]) { cb(); } else if (new Date().getTime() - timeStarted >= maxWaitTime) { timeoutCb(); } else { setTimeout(function() { waitFor(valueName, cb, timeoutCb, timeStarted); }, 500); } }; document.body.onload = function() { //On Consent Changed waitFor( "OneTrust", function() { //Found Handler window.OneTrust.OnConsentChanged(function(e) { onChangeCbs.forEach(function(cb) { cb(getCookieCategories(e.detail)); }); }); }, function() { //Timeout Handler console.error("Failed to find OneTrust after 30 seconds."); } ); //Return which groups are active waitFor( "OnetrustActiveGroups", function() { //Found Handler var cookieCategories = getCookieCategories( window.OnetrustActiveGroups.split(",") ); getSavedCbs.forEach(function(cb) { cb(cookieCategories); }); Object.keys(cookieCategories) .filter(function(category) { return cookieCategories[category] && activeCategoryCbs[category]; }) .forEach(function(category) { while (activeCategoryCbs[category].length > 0) { activeCategoryCbs[category].pop()(); } }); }, function() { //Timeout Handler console.error("Failed to find OnTrust Active Groups after 30 seconds."); getSavedCbs.forEach(function(cb) { cb(getCookieCategories([])); }); } ); }; })();